{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    {if condition="$data['id']!=''"}
                    <form method="post" class="form-horizontal" id="layer-form">
                        <input type="hidden" value="{$data['id']}" name="id">
                        <!--表单项-->
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><span class="text-danger">*</span>文件名</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="name" id="fileName" value="{$data['name']}"
                                       placeholder="请输入文件名"
                                >
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">描述</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="about" value="{$data['about']}"
                                       placeholder="请输入描述内容">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <!--/表单项-->

                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">
                                <button class="btn btn-primary" id="btn_sub" type="button">保存</button>
                                <button class="btn btn-white" type="button" onclick="history.go(-1);">取消</button>
                            </div>
                        </div>
                    </form>
                    {else/}
                    <form method="post" class="form-horizontal" id="file-form" action="upload" enctype="multipart/form-data" onsubmit="return saveReport();">
                        <!--表单项-->
                        <div class="form-group">
                            <label class="col-sm-2 control-label">描述</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="about"  value="" placeholder="请输入描述内容">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><span class="text-danger">*</span>文件</label>
                            <div class="col-sm-10">
                                <input id="file-1" type="file" name="file[]" multiple>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <!--/表单项-->

                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">
                                <button class="btn btn-primary" type="submit">保存</button>
                                <button class="btn btn-white" type="button" onclick="layer_close()">取消</button>
                            </div>
                        </div>
                    </form>
                    {/if}
                </div>
            </div>
        </div>
    </div>
</div>
</body>
{include file="public/footer" /}
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
    $(function () {
        //图片上传设置
        var path="/admin/sys.file/upload";
        initFileInput1("file-1",path);
    });

    function initFileInput1(ctrlName,uploadUrl) {
        var control = $('#' + ctrlName);
        control.fileinput({
            language: 'zh', //设置语言
            uploadUrl: uploadUrl,  //上传地址
            showUpload: false, //是否显示上传按钮
            enctype: 'multipart/form-data',
            showRemove:true,
            dropZoneEnabled: true,
            showCaption: true,//是否显示标题
            allowedPreviewTypes: ['image','video', 'flash'],
            allowedFileTypes: ['image', 'html', 'text', 'video', 'audio', 'flash', 'object'] ,
            allowedFileExtensions:  ['flv', 'swf', 'mkv', 'avi', 'rm', 'rmvb', 'mpeg', 'mpg', 'ogg', 'ogv', 'mov', 'wmv', 'mp4', 'webm', 'mp3'],
            maxFileSize : 200000,
            maxFileCount: 100,
            maxFilesNum: 100
        }).on("filebatchselected", function(event, files) {
            //$(this).fileinput("upload");
        }).on("fileuploaded", function(event, data) {
            //console.log(data);
        });
    }

    /**
     * 异步提交
     * @returns {boolean}
     */
    function saveReport() {
        //判空
        var files=$("#file-1").val();
        if(files==""){
            layer.msg("文件不能为空",{icon: 2});
            return false;
        }

        // jQuery 表单提交
        $("#file-form").ajaxSubmit(function(res) {
            var obj = eval('(' + res + ')');
            // 对于表单提交成功后处理，message为提交页面saveReport.htm的返回内容
            if(obj.rc==0){
                //刷新列表
                var tableName=$('#tableName', parent.document).val();
                parent.refreshTable(tableName);
                parent.toastr.success("操作成功！");
                //关闭弹窗
                layer_close();
            }else{
                layer.msg(obj.msg,{icon: 2});
            }
        });

        return false; // 必须返回false，否则表单会自己再做一次提交操作，并且页面跳转
    }

</script>
<!--/请在上方写此页面业务相关的脚本-->
